﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace PlantsVsZombies
{
    public class LoadBar3D : LoadBar
    {
        private Texture2D _sodRollCap;

        public Texture2D SodRollCap
        {
            get { return _sodRollCap; }
            set { _sodRollCap = value; }
        }
        private Vector2 _sodRollCapPostion;
        public LoadBar3D(Vector2 paramLoadBarPosition) : base(paramLoadBarPosition)
        {
            _sodRollCapPostion = Vector2.Zero;
        }
        public void LoadContent(
            ContentManager content,
            string strGrass,
            string strSodRoll,
            string strSodRollCap)
        {
            Grass = content.Load<Texture2D>(strGrass);
            Roll = content.Load<Texture2D>(strSodRoll);
            SodRollCap = content.Load<Texture2D>(strSodRollCap);
            
        }


        public void Update(GameTime gameTime)
        {
            m_RollPosition = new Vector2(40 + LoadBarPosition.X + m_Progress * 360,
                                         50 + LoadBarPosition.Y + Roll.Height * m_Progress * 0.5f);
            _sodRollCapPostion = m_RollPosition;

            m_RollRotation = m_Progress * 10;
            m_RollScale = 1 - m_Progress;
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            //DrawGround
            if (Ground != null) 
                spriteBatch.Draw(Ground, new Vector2(LoadBarPosition.X, LoadBarPosition.Y + 80), Color.White);
            
            spriteBatch.Draw(Grass, 
                             new Vector2(LoadBarPosition.X, LoadBarPosition.Y + 80),
                             new Rectangle(0, 0, (int)(m_RollPosition.X - LoadBarPosition.X), (Grass.Height)),
                             Color.White,
                             0,
                             new Vector2(0, 0),
                             new Vector2(1, 0.25f),
                             SpriteEffects.None,
                             0);    

            spriteBatch.Draw(Roll, 
                             m_RollPosition, 
                             null,
                             Color.White,
                             m_RollRotation,
                             new Vector2(Roll.Width / 2, Roll.Height / 2), m_RollScale, 
                             SpriteEffects.None, 
                             0);
        }


    }
}
